<?php
namespace Admin\Controller;
class PersonController extends AdminBaseController
{

    /***
     * @privilege Admin:个人信息->编辑:32579463707
     */
    public function edit()
    {
        if (IS_POST) {
            $data = I('post.data');
            $this->_editData('Person', $data);
        } else {
            $data['id'] = $this->uid;
            $info = $this->_detail('admin', $data);
            $this->assign([
                'info' => $info
            ]);
            $this->_display('add', '个人信息编辑');
        }
    }

    /***
     * @privilege Admin:个人信息->编辑密码:26822600594
     */
    public function editPass()
    {
        if (IS_POST) {
            $data = I('post.');
            $_valida = array(
                array('oldPass', 'require', '原始密码不能为空', 1),
                array('newPass', 'require', '新密码不能为空', 1),
                array('newPassRep', 'newPass', '确认密码不正确', 1, 'confirm'), // 验证确认密码是否和密码一致
            );
            $adminModel = M('admin');
            if ($adminModel->validate($_valida)->create($data) === false) {
                $this->error($adminModel->getError());
            }
            $uid = $this->uid;
            $userInfo = $adminModel->where("id = $uid")->find();
            if (password_verify($data['oldPass'], $userInfo['upass'])) {
                $saveData['upass'] = password_hash($data['newPass'], PASSWORD_DEFAULT);
                $rst = $adminModel->where("id = $uid")->save($saveData);
                if ($rst !== false) {
                    session_unset();
                    session_destroy();
                    $this->success("修改成功,请重新登录", U('public/login'));
                } else {
                    $this->error($adminModel->getDbError());
                }
            } else {
                $this->error('原始密码不正确!');
            }

        } else {

            $this->_display('edit_pass', '修改密码');
        }
    }

    /***
     * @privilege Admin:个人信息->删除:64903289090
     */
    public function del()
    {

        $this->_delAll('Person');
    }

}